<template>
	<view class="">
		<basetab name='收货地址'></basetab>
		<view class="p-30">
			<view class="address-item p-30 fl-s-s" @click="chooseAddress(item)" v-for="(item,index) in list" :key="index">
				<view class="fr-s-c w-1">
					<text class="text-line-1">{{item.name}}</text>
					<text class="phone fs-32 m-l-40 flex-1">{{item.phone}}</text>
				</view>
				<view class="fr-b-c" style="width: 100%;">
					<image v-if="index==0" style="width: 40rpx;height: 40rpx;" src="../../static/my/dizhi.png" mode=""></image>
					<view style="width: 40rpx;height: 40rpx;" v-else>
						
					</view>
					<view  class="c-33 fs-26 m-t-20 m-l-10" style="width: 560rpx;">{{item.city+item.address}}希望城D3四单元201希望城D3四单元201希望城D3四单元201</view>
					<image @click.stop="toEdit(item.id)" src='../../static/my/edrit.png' class="select-img"></image>
				</view>
				<image src="../../static/my/color_bar.png" class="m-t-20"
					style="height: 10rpx; width: 690rpx; margin-left: -25rpx;"></image>
				<view class="fr-s-c w-1 m-t-30">
					<view class="flex-1 fr-s-c" @click.stop="setDetault(item.id)">
						<image :src="item.id==address_id?selected:select" class="circle select-img"></image>
						<text class="c-77 fs-26 m-l-20">设为默认地址</text>
					</view>
					
					<view class="fr-s-c m-l-30" @click.stop="delAddress(item.id)">
						<text class="c-55 fs-28 m-l-10" style="font-size: 20rpx;font-weight: 700;color: rgba(212, 48, 48, 1);">删除</text>
					</view>
				</view>
			</view>
			<navigator url="/my-bus/AddressList/AddressList" hover-class="none" class="fr-c add-btn c-ff fs-32">
				添加收货地址
			</navigator>
		
			<view class="w-1 fl-s-c p-t-250" v-if="nodata">
			    <u-empty mode="address"></u-empty>
			</view>
			
		</view>
	</view>
	
</template>

<script>
import basetab from '../../componets/bartop.vue'
	export default {
		components:{
		
			basetab
		
		},
		data() {
			return {
				select: '../../static/my/select.png',
				selected:'../../static/my/selectend.png',
				list:[
					{
						name:'2121',
						phone:'1555555555',
						city:'北京市',
						address:'南京区',
						id:0
					},
					{
						name:'2121',
						phone:'1555555555',
						city:'北京市',
						address:'南京区',
						id:1
					}
				],
				nodata:false,
				address_id:0,
				ischoose:0,
				order_id:0,   // 订单id 
			}
		},
		onLoad(o) {
			this.order_id = o.order_id || 0
			this.ischoose = o.ischoose || 0;
			// this.getlist()
		},
		methods: {
			onRefresh(){
				this.getlist()
			},
			// 地址列表
			getlist(){
				this.$get({
					url:'/address/index'
				}).then(res=>{
					this.list = res.data.list
					this.nodata = !this.list.length
					this.address_id = res.data.address_id
				}).catch(err=>{
					this.list = []
					this.nodata = !this.list.length
					this.address_id = 0
				})
			},
			// 去编辑
			toEdit(id){
				uni.navigateTo({
					url:'/my-bus/AddressList/AddressList'
				})
			},
			// 设置默认
			setDetault(id){
				this.address_id=id
			
			},
			// 删除地址
			delAddress(id){
				uni.showModal({
					title:'提示',
					content:'确定删除该地址吗？',
					success: (res) => {
						if(res.confirm){
							this.$post({
								url:'/address/delete',
								data:{id}
							}).then(res=>{
								this.list = this.list.filter(item=>item.id!=id);
								this.nodata = !this.list.length
							})
						}
					}
				})
			},
			// 选择收货地址
			chooseAddress(item){
				if(this.ischoose==1 && !this.order_id){
					this.$lastVal('adinfo',item)
					uni.navigateBack()
					return
				}
				if(this.ischoose==1 && this.order_id){
					this.$post({
						url:'/order/editAddress',
						data:{
							order_id:this.order_id,
							address_id:item.id
						}
					}).then(res=>{
						getApp().tt('修改成功','success')
						// this.$lastVal('info.name',132)
						// this.$lastVal('info.phone',item.phone)
						// this.$lastVal('info.address',item.city + item.address)
						this.$lastMethod('getInfo')
						
						this.$delayBack()
						// this.$lastVal('adinfo',item)
						// uni.navigateBack()
						// return
					})
					
					
					
				}
			}
		}
	}
</script>

<style>
page{
	background: #f5f5f5;
	padding-bottom: 150rpx;
}
.address-item{
	width: 690rpx;
	background: #FFFFFF;
	border-radius: 10rpx;
	margin-bottom: 30rpx;
}
.phone{
	color: #DD5757;
}
.select-img{
	width: 30rpx;
	height: 30rpx;
	
}
.add-btn{
	position: fixed;
	left: 30rpx;
	bottom: 60rpx;
	width: 690rpx;
	height: 90rpx;
	background: linear-gradient(270deg, rgba(255, 101, 61, 1) 0%, rgba(255, 136, 0, 1) 100%);
	/* box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.12); */
	border-radius: 45rpx;
}
</style>
